package com.fxkj.cloud.drms.ui.listener;

import com.fxkj.cloud.dbs.common.event.stream.RemoteAlarmAttributeCreateEvent;
import com.fxkj.cloud.drms.application.ProductApplicationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.function.Consumer;

/**
 * <p>description: </p>
 * @author ww
 * @date 2025/4/7 13:04
 */
@Component
@Slf4j
public class RemoteAlarmAttributeCreateListener  {

    private final ProductApplicationService productApplicationService;

    public RemoteAlarmAttributeCreateListener(ProductApplicationService productApplicationService) {
        this.productApplicationService = productApplicationService;
    }

    @Bean
    public Consumer<RemoteAlarmAttributeCreateEvent> alarmAttributeCreate() {
        return event -> {
            log.trace("收到远程产品报警设置创建事件:{}", event);
            productApplicationService.addProductAttribute(event.getProductId(), event.getKeyMap(), event.getDeviceSerialNos(), event.getProductAlarmItemCreates());
        };
    }
}
